//
//  CubeLogoutPlugin.m
//  Module
//
//  Created by Fanty on 14-1-3.
//  Copyright (c) 2014年 Fanty. All rights reserved.
//

#import "CubeLogoutPlugin.h"

#import <chameleon-ios-sdk/CApplication.h>
#import <MainModuleSDK/DataCenter.h>

#import "CubeModule.h"
#import <MainModuleSDK/AsyncTask.h>
#import <SVProgressHUD/SVProgressHUD.h>

@implementation CubeLogoutPlugin

-(void)logout:(CDVInvokedUrlCommand*)command{
    NSString* callbackId=command.callbackId;
    
    [DataCenter defaultCenter].accountToken=nil;
    [DataCenter defaultCenter].username=nil;
    [DataCenter defaultCenter].roles=nil;
    
    CubeModule* cubeModule=(CubeModule*)[[CApplication sharedApplication] moduleForIdentifier:@"Module"];
    [cubeModule.accountManager cancelSync];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CubeAuth_Success" object:nil];
    
    CDVPluginResult*pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@""];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
}

@end
